package rmi;

import java.text.SimpleDateFormat;
import java.util.Date;

import rmi.Message.Type;

/*
 * 
 */
public class Log {
	public static enum Action{
	   emmi,recpt,delivr
	}
	private String logText;
	
	public Log(int listclient[],Action a,Message msg)
    {
    	logText=init(listclient, a, msg);
    }
	
    public String init(int listclient[],Action a,Message msg)
    {
    	int idClient = msg.getId();
    	char separator='|';	
    	String text="";
    	//init tmp pour l'operation
    	String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    	text=text+date+separator;
    	//init type action
    	switch(a){
    		case emmi:
    			if(msg.getType()==Type.Ligne||msg.getType()==Type.Ellipse)
    				text=text+" Client"+idClient+" dessine une "+msg.getType()+separator;
    			else
    				text=text+" Client"+idClient+" dessine un "+msg.getType()+separator;
    			break;
    		case recpt:
    			for(int i=0;i<listclient.length;i++)
    			{
    				text=text+"Client"+listclient[i]+" recu un message de client"+idClient;
    			}
    			break;
    		case delivr:
    			
    			text=text+"Client"+idClient+" delivrer une message a client ";
    			for(int i=0;i<listclient.length;i++)
    			{
    				text=text+listclient[i]+",";
    			}
    			text=text.substring(0, text.length()-1);
    			break;
    	}	
    	return text;
    }
    public String getLogText() {
		return logText;
	}
 
}
